package base.reflection_demo.demo_04;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Method;

/**
 * 通过反射调用两数加法运算,得到计算结果
 */
@Slf4j
public class ReflectDemo04 {
    public static void main(String[] args) throws Exception {
        Class<ReflectDemo04> clazz = ReflectDemo04.class;
        Method addMethod = clazz.getDeclaredMethod("add", int.class, int.class);
        int result = (int)addMethod.invoke(new ReflectDemo04(), 2, 3);
        log.info("result: {}",result);
    }

    public int add(int a, int b){
        return a + b;
    }
}
